package controllers

import (
	"fmt"
	"github.com/gin-gonic/gin"
	bizcode "mall-api-gin/pkg/bizerror"
	"mall-api-gin/pkg/e"
	"mall-api-gin/service"
	"net/http"
)

type SmsController struct {
	BaseController
}

func (con SmsController) Index(ctx *gin.Context) {
	defer con.PanicHandler(http.StatusOK)
	con.C = ctx

	//sms := Sms.Aliyun{}
	//result, err := sms.Send("18675343869")
	result, err := service.SmsService.Send("18675343869")
	if err != nil {
		con.ErrResponse(http.StatusOK, e.ERROR, fmt.Sprintf("发送短信验证码失败：%v\n", err))
	}

	con.Response(http.StatusOK, bizcode.SUCCESS, gin.H{
		"result": result,
	})
}

func (con SmsController) Verify(ctx *gin.Context) {
	defer con.PanicHandler(http.StatusOK)
	con.C = ctx

	result, err := service.SmsService.Verify("18675343869", "8432")
	if err != nil {
		con.ErrResponse(http.StatusOK, e.ERROR, fmt.Sprintf("短信验证码错误：%v\n", err))
	}

	con.Response(http.StatusOK, bizcode.SUCCESS, gin.H{
		"result": result,
	})
}
